package io.renren.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.dao.ChatmemberDao;
import io.renren.dto.ChatmemberDTO;
import io.renren.entity.ChatmemberEntity;
import io.renren.service.ChatmemberService;
import cn.hutool.core.util.StrUtil;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * ${comments}
 *
 * @author Sen 524227263@qq.com
 * @since 1.0.0 2024-07-25
 */
@Service
public class ChatmemberServiceImpl extends CrudServiceImpl<ChatmemberDao, ChatmemberEntity, ChatmemberDTO> implements ChatmemberService {

    @Override
    public QueryWrapper<ChatmemberEntity> getWrapper(Map<String, Object> params) {
        String id = (String) params.get("id");

        QueryWrapper<ChatmemberEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StrUtil.isNotBlank(id), "id", id);

        return wrapper;
    }


    @Override
    public List<ChatmemberEntity> getListByGroupId(String groupId) {
        QueryWrapper<ChatmemberEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("ChatGroupId", groupId);
        wrapper.eq("IsAdmin", 2);
        return baseDao.selectList(wrapper);
    }

    @Override
    public void deleteByGroupId(String groupId) {
        QueryWrapper<ChatmemberEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("ChatGroupId", groupId);
        wrapper.eq("IsAdmin", 2);
        baseDao.delete(wrapper);
    }
}